package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.GrouponCatalogDto;
import com.ymatou.iapi.productmanager.parameter.SaveGrouponBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.CatalogSaveModel;
import com.ymatou.iapi.productmanager.parameter.product.ModifySellerProductRequest;
import com.ymatou.iapi.productmanager.service.SaveGrouponCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.ActivityCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.database.model.GrouponCatalogs;
import com.ymttest.database.model.GrouponProducts;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import org.apache.http.client.ClientProtocolException;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 微信公众号登录（全球优选） FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_SaveGroupon {
	private static SaveGrouponBean savegrouponBean;
	private static SaveGrouponCall savegrouponCall;
	private static YmtProductsIWapper YmtProductsIWapper ;
	/**
	 * 非优选
	 */
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("autotest_seller1"));
	/**
	 * 优选
	 */
	private static Integer sellerId2 = 3383;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建编辑拼团");
	}

	@Before
	public void caseUp() {
		savegrouponBean = new SaveGrouponBean();
		savegrouponCall = new SaveGrouponCall();
		YmtProductsIWapper= new YmtProductsIWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(savegrouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void setStock(AddSellerProductRequest addpro, Integer catalogNum) {
		addpro.getProduct().getCatalogList().forEach(catalog -> {
			catalog.setStock(catalogNum);
		});
	}

	private void setPrice(AddSellerProductRequest addpro, Double price) {
		addpro.getProduct().getCatalogList().forEach(catalog -> {
			catalog.setNewPrice(price);
			catalog.setMarketPrice(price);
			catalog.setVipPrice(price);
			catalog.setPrice(price);
		});
	}

	/**
	 * @param savegrouponBean2
	 * @return getGrouponProductId
	 */
	private Integer verifyDB(SaveGrouponBean savegrouponBean2,boolean isModify) throws InterruptedException {
		List<GrouponProducts> gp = YmtProductsIWapper.selectGrouponProducts(savegrouponBean2.getProductId(), null, 0);
		Logger.verifyEquals(1, gp.size(), "验证当前有效拼团数量");
		if (savegrouponBean2.getGrouponMemberCount()!=0&&savegrouponBean2.getGrouponMemberCount()>=2){
			Logger.verifyEquals(savegrouponBean2.getGrouponMemberCount(), gp.get(0).getGrouponMemberCount(), "验证当前拼团人数");
		}else{
			Logger.verifyEquals(2, gp.get(0).getGrouponMemberCount(), "验证当前拼团人数");
		}
		Long version = gp.get(0).getVersion();
		
		savegrouponBean2.getGrouponCatalogs().forEach(gc -> {
			List<GrouponCatalogs> catalogs = YmtProductsIWapper.selectGrouponCatalogs(gc.getCatalogId(), version.intValue());
			Logger.verifyEquals(1, catalogs.size(), "验证有数据CatalogId:" + gc.getCatalogId());
			Logger.verifyEquals(new BigDecimal(gc.getGrouponPrice()).setScale(2), catalogs.get(0).getGrouponPrice().setScale(2), "验证价格");
		});

		Thread.sleep(5000);
		String actionType = "CreateGroupon";
		String actionType1 = "ModifyGrouponPrice";
		Logger.debug(actionType+"_"+gp.get(0).getVersion());
		List<Map> businessCredentialInfoMap = YmtProductsIWapper.selectBusinessCredentialInfo(savegrouponBean2.getProductId(),actionType,gp.get(0).getVersion());
		Logger.debug("businessCredentialInfoMap:"+businessCredentialInfoMap);
		if(isModify){
			List<Map> businessCredentialInfoMap1 = YmtProductsIWapper.selectBusinessCredentialInfo(savegrouponBean2.getProductId(),actionType1,gp.get(0).getVersion());
			Logger.verifyEquals(gp.get(0).getGrouponProductId(),businessCredentialInfoMap1.get(0).get("LiveId"),"验证拼团商品自增id");
			Logger.verifyEquals(sellerId2,businessCredentialInfoMap1.get(0).get("SellerId"),"验证sellerId");
		}else{
			Logger.verifyEquals(gp.get(0).getGrouponProductId(),businessCredentialInfoMap.get(0).get("LiveId"),"验证拼团商品自增id");
			Logger.verifyEquals(sellerId2,businessCredentialInfoMap.get(0).get("SellerId"),"验证sellerId");
		}


		return gp.get(0).getGrouponProductId();

	}

	/**
	 * 验证砍价团总线
	 * @param getGrouponProductId
	 * @param pid
	 * @param qcode
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	private void verifyGroupMq(Integer getGrouponProductId, String pid,String qcode) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(1000);
		MessageListBean MessageListBean = MqQueryCallService.initGroupon(pid, qcode);
		List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
		Logger.debug(joa);
		// {"EndTime":"4000-01-31
		// 23:59:00","GroupExpiredHours":6,"GroupMemberCount":2,"GrouponProductId":33,"ProductId":"p1158472"}
		Logger.comment("验证砍价团总线消息");
		Logger.verifyEquals(6, joa.get(0).get("GroupExpiredHours"), "验证GroupExpiredHours");
		List<GrouponProducts> gp = YmtProductsIWapper.selectGrouponProducts(pid, null, 0);

		Logger.verifyEquals(gp.get(0).getGrouponMemberCount(), joa.get(0).get("GroupMemberCount"), "验证GroupMemberCount");
		Logger.verifyEquals(getGrouponProductId, joa.get(0).get("GrouponProductId"), "验证GrouponProductId");
		Logger.verifyNotNull(joa.get(0).get("EndTime"), "验证EndTime");
		Logger.verifyNotNull(joa.get(0).get("BeginTime"), "验证EndTime");
		Logger.verifyEquals(pid, joa.get(0).get("ProductId"), "验证ProductId");
	}
	/**
	 * 验证同步指令
	 * @param getGrouponProductId
	 * @param pid
	 * @param code
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 * @throws InterruptedException 
	 */
	private void verifyMongoCurMq(Integer getGrouponProductId, String pid, String code) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(1000);
		List<GrouponProducts> gp = YmtProductsIWapper.selectGrouponProducts(savegrouponBean.getProductId(), null, 0);
		String version = gp.get(0).getVersion().toString();
		MessageListBean MessageListBean2 = MqQueryCallService.initPMongoCrud(pid);
		List<Map> joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
		Logger.debug(joa2);
		Logger.verifyEquals(code, joa2.get(0).get("ActionType"), "验证ActionType");
		Logger.verifyEquals(getGrouponProductId, joa2.get(0).get("ActivityId"), "验证ActivityId");
		Logger.verifyEquals(version, joa2.get(0).get("ExtParam"), "验证ExtParam-version");
		// [{"ActionType":"CreateGroupon","ActivityId":33,"AppId":"productmanager.iapi.ymatou.com","ExtParam":"2013","ProductId":"p1158472","SellerId":0,"TransactionId":2611926},
		// {"ActionType":"CreateProduct","ActivityId":0,"AppId":"productmanager.iapi.ymatou.com","ProductId":"p1158472","SellerId":0,"TransactionId":2611925}]
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_SaveGroupon_001() {
		Logger.start(true, "优选买手创建拼团成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer getGrouponProductId = verifyDB(savegrouponBean,false);
			
			verifyGroupMq(getGrouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_002() {
		Logger.start(true, "非优选买手创建拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyEquals("非优选买手不能创建拼团", savegrouponCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_003() {
		Logger.start(true, "买手创建拼团，单规格商品规格总库存小于20，创建拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 1);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("总规格库存不得低于", savegrouponCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_004() {
		Logger.start(true, "买手创建拼团，多规格商品部分规格总库存小于20，总库存大于20，创建拼团成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 1);
			addpro.getProduct().getCatalogList().get(0).setStock(19);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			// 总库存大于20应该可以
			Integer getGrouponProductId = verifyDB(savegrouponBean,false);
			
			verifyGroupMq(getGrouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	@Ignore
	// 这个在前端判断
	public void Tc_SaveGroupon_005() {
		Logger.start(true, "买手创建拼团，单规格商品最高价大于300，创建拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setPrice(addpro, 400d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	@Ignore
	public void Tc_SaveGroupon_006() {
		Logger.start(true, "买手创建拼团，下架商品，创建拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setPrice(addpro, 400d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			ProductManagerCallServiceV2.batchSetProductOffSale(Arrays.asList(pid), sellerId2);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			// 下架商品不能参加
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_007() {
		Logger.start(true, "买手创建拼团，无效商品，创建拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setPrice(addpro, 400d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			ProductManagerCallServiceV2.batchDeleteProducts(Arrays.asList(pid), sellerId2);
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			// 无效的商品 展示已删除
			Logger.verifyEquals("商品已被删除", savegrouponCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_008() {
		Logger.start(true, "买手创建拼团，商品中含有无效规格，创建拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setPrice(addpro, 400d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			ProductManagerCallServiceV2.batchSetProductOffSale(Arrays.asList(pid), sellerId2);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				// 无效的cid
				e.setCatalogId("1234567");
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyEquals("团规格不存在或已被删除", savegrouponCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_009() {
		Logger.start(true, "买手创建拼团，部分规格商品参与拼团，创建拼团成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setPrice(addpro, 400d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			GrouponCatalogDto e = new GrouponCatalogDto();
			// 部分规格报名
			e.setCatalogId(catalogs.get(0));
			e.setGrouponPrice(70d);
			grouponCatalogs.add(e);
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer getGrouponProductId = verifyDB(savegrouponBean,false);
			
			verifyGroupMq(getGrouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_010() {
		Logger.start(true, "买手创建拼团，单规格商品拼团价大于原价，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			addpro.getProduct().getCatalogList().remove(1);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(170d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("团规格价格需设置不合理", savegrouponCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_011() {
		Logger.start(true, "买手创建拼团，多规格商品部分规格拼团价大于原价，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(170d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("团规格价格需设置不合理", savegrouponCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_012() {
		Logger.start(true, "买手创建拼团，单规格商品拼团价>max（规格码头价*90%，规格码头价-10元），码头价200，拼团价191，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 200d);
			addpro.getProduct().getCatalogList().remove(1);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(191d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("团规格价格需设置不合理", savegrouponCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_0122() {
		Logger.start(true, "买手创建拼团，单规格商品拼团价>max（规格码头价*90%，规格码头价-10元），码头价200，拼团价190，拼团成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 200d);
			addpro.getProduct().getCatalogList().remove(1);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(190d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer getGrouponProductId = verifyDB(savegrouponBean,false);

			verifyGroupMq(getGrouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_0121() {
		Logger.start(true, "买手创建拼团，单规格商品拼团价>max（规格码头价*90%，规格码头价-10元），码头价50，拼团价46，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 50d);
			addpro.getProduct().getCatalogList().remove(1);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(46d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("团规格价格需设置不合理", savegrouponCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_013() {
		Logger.start(true, "买手创建拼团，单规格商品拼团价=max（规格码头价*90%，规格码头价-10元），码头价50，拼团价45，拼团成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 50d);
			addpro.getProduct().getCatalogList().remove(1);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(45d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer getGrouponProductId = verifyDB(savegrouponBean,false);

			verifyGroupMq(getGrouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_014() {
		Logger.start(true, "买手创建拼团，多规格商品部分规格拼团价>max（规格码头价*90%，规格码头价-10元），其中一个规格价格为50,拼团价为46，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 50d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			GrouponCatalogDto e1 = new GrouponCatalogDto();
			e1.setCatalogId(catalogs.get(0));
			e1.setGrouponPrice(46d);
			GrouponCatalogDto e2 = new GrouponCatalogDto();
			e2.setCatalogId(catalogs.get(0));
			e2.setGrouponPrice(45d);
			grouponCatalogs.add(e1);
			grouponCatalogs.add(e2);

			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("团规格价格需设置不合理", savegrouponCall.getString("Msg"), "验证Msg");


		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_015() {
		Logger.start(true, "买手创建拼团，多规格商品部分规格拼团价=max（规格码头价*90%，规格码头价-10元），其中一个规格价格为50,拼团价为45，拼团成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 50d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			GrouponCatalogDto e1 = new GrouponCatalogDto();
			e1.setCatalogId(catalogs.get(0));
			e1.setGrouponPrice(45d);
			GrouponCatalogDto e2 = new GrouponCatalogDto();
			e2.setCatalogId(catalogs.get(1));
			e2.setGrouponPrice(45d);
			grouponCatalogs.add(e1);
			grouponCatalogs.add(e2);

			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer getGrouponProductId = verifyDB(savegrouponBean,false);

			verifyGroupMq(getGrouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_0141() {
		Logger.start(true, "买手创建拼团，多规格商品部分规格拼团价>max（规格码头价*90%，规格码头价-10元），其中一个规格价格为200,拼团价为191，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 200d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			GrouponCatalogDto e1 = new GrouponCatalogDto();
			e1.setCatalogId(catalogs.get(0));
			e1.setGrouponPrice(191d);
			GrouponCatalogDto e2 = new GrouponCatalogDto();
			e2.setCatalogId(catalogs.get(1));
			e2.setGrouponPrice(190d);
			grouponCatalogs.add(e1);
			grouponCatalogs.add(e2);

			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("团规格价格需设置不合理", savegrouponCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_0142() {
		Logger.start(true, "买手创建拼团，多规格商品部分规格拼团价>max（规格码头价*90%，规格码头价-10元），其中一个规格价格为200,拼团价为190，拼团成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 200d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			GrouponCatalogDto e1 = new GrouponCatalogDto();
			e1.setCatalogId(catalogs.get(0));
			e1.setGrouponPrice(190d);
			GrouponCatalogDto e2 = new GrouponCatalogDto();
			e2.setCatalogId(catalogs.get(1));
			e2.setGrouponPrice(190d);
			grouponCatalogs.add(e1);
			grouponCatalogs.add(e2);

			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer getGrouponProductId = verifyDB(savegrouponBean,false);

			verifyGroupMq(getGrouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_017() {
		Logger.start(true, "买手创建拼团，商品已经参与拼团，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("已参与其他拼团", savegrouponCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_018() {
		Logger.start(true, "买手创建拼团，商品已经参与砍价团活动，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 3000);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			//创建一个砍价团活动
			Integer activityId = ActivityCallService.createActivityInProcess(MapUtil.hashMap("ActivityTemplateId",2));
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(pid, sellerId2,catalogs,activityId, 100,"100");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(pid,aids.get(0),true);

			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("商品已参加砍价团，不能创建拼团", savegrouponCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_019() {
		Logger.start(true, "买手创建拼团，商品已经报名砍价团活动还未审核通过，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 3000);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			//创建一个砍价团活动
			Integer activityId = ActivityCallService.createActivityInProcess(MapUtil.hashMap("ActivityTemplateId",2));
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(pid, sellerId2,catalogs,activityId, 100,"100");

			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyIsContains("商品已参加砍价团，不能创建拼团", savegrouponCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_020() {
		Logger.start(true, "编辑拼团，编辑拼团价格，编辑成功，检测商品和所有规格版本号");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			//String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);

			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer grouponProductId = verifyDB(savegrouponBean,false);
			verifyGroupMq(grouponProductId,pid,"create_groupon");
			//verifyMongoCurMq(grouponProductId,pid,"CreateGroupon");
			savegrouponBean.setGrouponProductId(grouponProductId);
			grouponCatalogs.forEach(cata -> {
				cata.setGrouponPrice(60d);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(1);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			grouponProductId = verifyDB(savegrouponBean,true);
			//// verifyMongoCurMq(grouponProductId,pid,"ModifyGrouponPrice");
			List<GrouponProducts> gp = YmtProductsIWapper.selectGrouponProducts(savegrouponBean.getProductId(), null, 0);
			Long version = gp.get(0).getVersion();
			int nowGrouponCatalogsize=YmtProductsIWapper.selectGrouponCatalogs(null, version.intValue()).size();
			Logger.verifyEquals(2, nowGrouponCatalogsize, "验证size："+version);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_021() {
		Logger.start(true, "编辑拼团，编辑拼团商品规格，增加规格，编辑成功，检测商品和所有规格版本号");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug("修改前："+FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			for (int i = 0; i < catalogs.size(); i++) {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogs.get(i));
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			}
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer grouponProductId = verifyDB(savegrouponBean,false);
			verifyGroupMq(grouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(grouponProductId,pid,"CreateGroupon");
			
			Logger.comment("添加一个规格然后在修改拼团");
			
			ModifySellerProductRequest modify = ProductManagerCallServiceV2.getModifySellerProductRequestFromAddProductBean(pid, addpro);
			CatalogSaveModel csm = ProductManagerCallServiceV3.initCatalogSaveModel();
			csm.setOperateType(1);
			csm.setNewPrice(70d);
			csm.setMarketPrice(70d);
			csm.setVipPrice(70d);
			csm.setPrice(70d);
			modify.getProduct().getCatalogList().add(csm);
			ProductManagerCallServiceV3.ModifySellerProduct(modify);
			//拼团
			savegrouponBean=new SaveGrouponBean();
			savegrouponBean.setGrouponProductId(grouponProductId);
			catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug("修改后："+FormatUtil.beanToGSONString(catalogs));
			grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			for (int i = 0; i < catalogs.size(); i++) {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogs.get(i));
				e.setGrouponPrice(60d);
				grouponCatalogs.add(e);
			}
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(1);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			grouponProductId = verifyDB(savegrouponBean,true);
			// verifyMongoCurMq(grouponProductId,pid,"ModifyGrouponPrice");
			List<GrouponProducts> gp = YmtProductsIWapper.selectGrouponProducts(savegrouponBean.getProductId(), null, 0);
			Long version = gp.get(0).getVersion();
			int nowGrouponCatalogsize=YmtProductsIWapper.selectGrouponCatalogs(null, version.intValue()).size();
			Logger.verifyEquals(3, nowGrouponCatalogsize, "验证size："+version);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_022() {
		Logger.start(true, "编辑拼团，编辑拼团商品规格，减少规格，编辑成功，检测商品和所有规格版本号");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer grouponProductId = verifyDB(savegrouponBean,false);
			verifyGroupMq(grouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(grouponProductId,pid,"CreateGroupon");
			
			Logger.comment("删除一个规格然后在修改拼团");
			savegrouponBean=new SaveGrouponBean();
			savegrouponBean.setGrouponProductId(grouponProductId);
			ModifySellerProductRequest modify = ProductManagerCallServiceV2.getModifySellerProductRequestFromAddProductBean(pid, addpro);
			modify.getProduct().getCatalogList().remove(0);
			ProductManagerCallServiceV3.ModifySellerProduct(modify);
			catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().filter(ele->{return ele.getiAction()!=-1;}).map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug("修改后："+FormatUtil.beanToGSONString(catalogs));
			ArrayList<GrouponCatalogDto> grouponCatalogs2 = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(60d);
				grouponCatalogs2.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs2);
			savegrouponBean.setOperateType(1);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			grouponProductId = verifyDB(savegrouponBean,true);
			// verifyMongoCurMq(grouponProductId,pid,"ModifyGrouponPrice");
			List<GrouponProducts> gp = YmtProductsIWapper.selectGrouponProducts(savegrouponBean.getProductId(), null, 0);
			Long version = gp.get(0).getVersion();
			List<GrouponCatalogs> grouponCatalogsList = YmtProductsIWapper.selectGrouponCatalogs(null, version.intValue());
			Logger.verifyEquals(1, grouponCatalogsList.size(), "验证size："+version);
			Logger.verifyEquals(0,grouponCatalogsList.get(0).getAction(),"验证参与拼团规格action");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	@Ignore
	//不是优选买手无法编辑团
	public void Tc_SaveGroupon_023() {
		Logger.start(true, "编辑拼团，买手不是优选买手，编辑失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer grouponProductId = verifyDB(savegrouponBean,false);
			verifyGroupMq(grouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(grouponProductId,pid,"CreateGroupon");
			savegrouponBean.setGrouponProductId(grouponProductId);
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(1);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");
			Logger.verifyEquals("非优选买手不能创建拼团", savegrouponCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_024() {
		Logger.start(true, "创建拼团，指定拼团人数，创建成功");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponBean.setGrouponMemberCount(3);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer getGrouponProductId = verifyDB(savegrouponBean,false);

			verifyGroupMq(getGrouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_025() {
		Logger.start(true, "创建拼团，指定拼团人数小于2，则默认拼团人数为2");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponBean.setGrouponMemberCount(1);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("Code"), "验证code");
			Integer getGrouponProductId = verifyDB(savegrouponBean,false);

			verifyGroupMq(getGrouponProductId,pid,"create_groupon");
			// verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_SaveGroupon_026() {
		Logger.start(true, "创建拼团，指定拼团人数小于2，则默认拼团人数大于100，拼团失败");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId2);
			setStock(addpro, 30);
			setPrice(addpro, 100d);
			String pid = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
			Logger.debug(FormatUtil.beanToGSONString(catalogs));
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogs.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(70d);
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setOperateType(0);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(sellerId2);
			savegrouponBean.setGrouponMemberCount(1001);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("Code"), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}